
/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// User.h
//

#pragma once

#include <BaseDefine.h>
#include <string>

/**
* @class User
*  - User class
*/
class Room;
class User{
	enum{
		DEF_USER_TYPE_NORMAL=		0,
		DEF_USER_TYPE_OBSERVER=		1,
	};

	enum{
		DEF_HAVE_NO_NETWORK=			0,
		DEF_HAVE_NETWORK=				1,
		DEF_HAVE_NETWORK_UNKNOWN=		2,
	};

public:
	virtual int extern_send( int type, char* data ) = 0;
	virtual int send( char* data, size_t size ) = 0;
	virtual int is_have_network(){ return DEF_HAVE_NETWORK_UNKNOWN; }

	const size_t getIdent(){ return ident_; }

	const char* getID(){ 
		if( id_.empty() )
			return "";

		return id_.c_str(); 
	}

	const char* getIP(){
		if( ip_.empty() )
			return "";
		return ip_.c_str();
	}

	const char* getPasswd(){ return passwd_.c_str(); }
	Room* getRoom(){ return room_; }

	void setIdent( size_t ident ){ ident_ = ident; }

	void setID( char* id ){ 
		if(! id )
			return;

		id_ = id; 
	}

	void setPasswd( char* passwd ){ 
		if(! passwd )
			return;

		passwd_ = passwd; 
	}	
	
	bool isLogin(){ return login_; }
	bool isTypeNormal();
	bool isTypeObserver();
	void setObserver();	
	void setNotObserver();
	void loginSuccess(){ login_ = true; }

	User();
	virtual ~User();

protected:
	void reset();

	size_t ident_;
	std::string id_;
	std::string passwd_;
	std::string ip_;
	size_t type_;
	bool login_;

private:
	Room* room_;

private:
	friend class RoomCreate_Default;
	friend class RoomEnter_Default;
	friend class RoomExit_Default;

	void setRoom( Room* room ){ room_ = room; }	
};
